package com.lxm.controller;


import com.lxm.dto.NickNamePwdLoginDTO;
import com.lxm.dto.PhoneCodeLoginDTO;
import com.lxm.dto.PhonePwdLoginDTO;
import com.lxm.dto.Result;
import com.lxm.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 用户登录表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-10-02
 */
@RestController
@RequestMapping("/user/login")
@Tag(name = "登录管理")
public class LoginController {
    @Resource
    private LoginService loginService;

    //这里由前端控制登录方式，如果是手机号登录，就发过来手机号和密码的加密JSON包
    //如果是昵称登录，就发过来昵称和密码的加密JSON包
    //设置三种登录方式，解耦合
    //这里最后都需要使用AOP进行解密操作
    @Operation(summary = "用户手机号登录")
    @PostMapping("/1")
    public Result loginByPhone(@RequestBody PhonePwdLoginDTO login, HttpServletResponse response) {
        return loginService.loginByPhone(login, response);
    }

    @Operation(summary = "用户昵称登录")
    @PostMapping("/2")
    public Result loginByNickName(@RequestBody NickNamePwdLoginDTO login, HttpServletResponse response) {
        return loginService.loginByNickName(login, response);
    }

    @Operation(summary = "用户手机号验证码登录")
    @PostMapping("/3")
    public Result loginByPhonedCode(@RequestBody PhoneCodeLoginDTO phoneCodeLoginDTO, HttpServletResponse response) {
        return loginService.loginByPhoneCode(phoneCodeLoginDTO, response);
    }

    @Operation(summary = "用户登出")
    @PostMapping("/logout")
    public Result logout(HttpServletRequest request) {
        return Result.ok(loginService.logout(request));
    }

}

